package com.xingchen.feima.star.controller;


import com.xingchen.feima.common.utils.R;
import com.xingchen.feima.star.entity.NuclearPowerPlant;
import com.xingchen.feima.star.service.NuclearPowerPlantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 核电站表 前端控制器
 * </p>
 *
 * @author yangxc
 * @since 2025-02-10
 */
@Api(tags = "核电站管理")
@RestController
@RequestMapping("/star/nuclearPowerPlant")
public class NuclearPowerPlantController {

    @Autowired
    private NuclearPowerPlantService nuclearPowerPlantService;


    @ApiOperation(value = "获取核电站列表")
    @GetMapping("")
    public R getList(){
        List<NuclearPowerPlant> list = nuclearPowerPlantService.list(null);
        return R.ok().data("items", list);
    }

    @ApiOperation(value = "新增核电站")
    @PostMapping("")
    public R add(
            @ApiParam(name = "nuclearPowerPlant", value = "核电站对象", required = true)
            @RequestBody NuclearPowerPlant nuclearPowerPlant){

        nuclearPowerPlantService.save(nuclearPowerPlant);
        return R.ok().message("添加成功");
    }

    @ApiOperation(value = "根据id查询核电站")
    @GetMapping("/{id}")
    public R getById(
            @ApiParam(name = "id", value = "核电站id", required = true)
            @PathVariable Long id){

        NuclearPowerPlant nuclearPowerPlant = nuclearPowerPlantService.getById(id);
        return R.ok().data("items", nuclearPowerPlant);
    }

    @ApiOperation(value = "根据id修改核电站")
    @PutMapping("")
    public R updateById(
            @ApiParam(name = "nuclearPowerPlant", value = "核电站对象", required = true)
            @RequestBody NuclearPowerPlant nuclearPowerPlant){

        nuclearPowerPlantService.updateById(nuclearPowerPlant);
        return R.ok().message("修改成功");
    }
    
    @ApiOperation(value = "根据id删除核电站")
    @DeleteMapping("/{id}")
    public R removeById(
            @ApiParam(name = "id", value = "核电站id", required = true)
            @PathVariable Long id){

        nuclearPowerPlantService.removeById(id);
        return R.ok().message("删除成功");
    }

    @ApiOperation("根据id列表批量删除核电站")
    @DeleteMapping("/batchRemove")
    public R batchRemove(
            @ApiParam(name = "idList", value = "id列表", required = true)
            @RequestBody List<Long> idList) {

        nuclearPowerPlantService.removeByIds(idList);
        return R.ok().message("批量删除成功");
    }
}

